home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / cfuncs.zip / WRITEAT.C < prev    next >
Text File  |  1991-08-07  |  3KB  |  103 lines

  1. #include <conio.h>
  2. #include <stdarg.h>
  3. int savX=1, savY=1, savATT;
  4.  
  5. /*---------------------Write AT-----------------------------*/
  6. /*                                                          */
  7. /* DESCRPTION: Writes a string to the console or screen     */
  8. /*              at the column and row in the foreground and */
  9. /*              background.                                 */
  10. /*                                                          */
  11. /* INPUT:                                                   */
  12. /*    X         - screen row       (1-25)                      */
  13. /*    Y      - screen column    (1-80)                      */
  14. /*    fore   - foreground color                             */
  15. /*    back   - background color                             */
  16. /*    format - format of outputted string in printf format  */
  17. /*    ...    - list of arguments                            */
  18. /*                                                          */
  19. /* USES: dma_puts                                           */
  20. /*----------------------------------------------------------*/
  21.  
  22. void WriteAt( int X, int Y, int fore, int back, char *format, ... )
  23. {
  24.   char outstr[81];
  25.   va_list arg_ptr;
  26.  
  27.   va_start(arg_ptr, format);
  28.   vsprintf(outstr, format, arg_ptr);
  29.  
  30.   dma_puts((savX=X), (savY=Y), (savATT=fore+(back<<4)), outstr);
  31.  
  32.   return;                    /*  Successful Return */
  33. }
  34.  
  35. /*---------------------------Write----------------------*/
  36. /*                            */
  37. /* DESCRIPTION: Must be preceeded by a call to WriteAt. */
  38. /*    Writes a string to the screen beginning a row   */
  39. /*    below the string written with WriteAt.        */
  40. /*                            */
  41. /* USES: dma_puts                      */
  42. /* IN: writeat.c                    */
  43. /*------------------------------------------------------*/
  44.  
  45. void Write(char *format, ...)
  46. {
  47.   char outstr[81];
  48.   va_list arg_ptr;
  49.  
  50.   va_start(arg_ptr, format);
  51.   vsprintf(outstr, format, arg_ptr);
  52.  
  53.   dma_puts(savX, ++savY, savATT, outstr);
  54. }
  55.  
  56.  
  57. /*-------------------------WriteDS-----------------------*/
  58. /*                             */
  59. /* DESCRIPTION: Must be preceeded by a call to WriteAt.  */
  60. /*    Writes a string to the screen beginning two rows */
  61. /*    below the string written with WriteAt.         */
  62. /*                             */
  63. /* USES: dma_puts                     */
  64. /* IN: writeat.c                     */
  65. /*-------------------------------------------------------*/
  66.  
  67. void WriteDS(char *format, ...)
  68. {
  69.   char outstr[81];
  70.   va_list arg_ptr;
  71.  
  72.   va_start(arg_ptr, format);
  73.   vsprintf(outstr, format, arg_ptr);
  74.  
  75.   savY += 2;
  76.   dma_puts(savX, savY, savATT, outstr);
  77. }
  78.  
  79. /* #include <time.h>
  80. main()
  81. {
  82.    clock_t start, end;
  83.    register int i;
  84.  
  85.    start = clock();
  86.    for(i=0; i<3000; ++i)
  87.      writeatf(10, 6, BLUE, GREEN, "hi world from writeatf .");
  88.    end = clock();
  89.    printf("time for writeatf was : %f\n", (end-start) / CLK_TCK);
  90.  
  91.    start = clock();
  92.    for(i=0; i<3000; ++i)
  93.      writeatf(10, 8, BLUE, GREEN, "hi world from writeatf %d.", -6);
  94.    end = clock();
  95.    printf("time for writeatf was : %f\n", (end-start) / CLK_TCK);
  96.  
  97.    start = clock();
  98.    for(i=0; i<3000; ++i)
  99.      WriteAt(10, 10, BLUE, GREEN, "hi world from WriteAt %d.");
  100.    end = clock();
  101.    printf("time for WriteAt was : %f\n", (end-start) / CLK_TCK);
  102.  
  103. }  */